package WEB.Servlet.Actions;

import java.util.HashMap;
import java.util.Map;


public class ActionFactory {
     protected Map map = defaultMap();

     public ActionFactory() {
          super();
     }
     public Action create(String actionName) {
          Class klass = (Class) map.get(actionName);
          if (klass == null)
               throw new RuntimeException(getClass() + " was unable to find	an action named "
                       + actionName + "'.");

          Action actionInstance = null;
          try {
               actionInstance = (Action) klass.newInstance();
          } catch (Exception e) {
               e.printStackTrace();
          }

          return actionInstance;
     }
     protected Map defaultMap() {
          Map map = new HashMap();
          map.put("index", BootstrapAction.class);
          map.put("login", LoginAction.class);
          map.put("show", ShowAction.class);
          map.put("ShowAction", ShowAction.class);
          map.put("addIntake", AddIntake.class);
          map.put("delIntake", DelIntake.class);
          return map;
     }
}